package com.gf.pf.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.gf.pf.model.Dictionary;
import com.gf.pf.model.Ztree;

/**
 * @describe 基本信息-字典信息
 * @author   WLxing
 * @date     2015年3月10日
 */
public interface DictionaryMapper {
	
	/**
	 * 根据ID查询字典SQL
	 */
	final String GET_BY_ID = "SELECT dic_id as id, dic_name, dic_parent_id, dic_remark, dic_orderno, dic_isvalid FROM sys_dictionary WHERE dic_id = #{dicId} ORDER BY dic_orderno";
	
	/**
	 * 根据ID查询根目录下的字典
	 */
	final String GET_ZTREE_BY_ID = "SELECT dic_id as id, dic_parent_id as pId, dic_name as name FROM sys_dictionary WHERE dic_isvalid = 1 start with dic_parent_id = '-1' connect by prior dic_id = dic_parent_id ORDER BY dic_orderno";
	
	/**
	 * 保存字典信息SQL
	 */
	final String SAVE_DIC = "INSERT　INTO sys_dictionary VALUES(#{id}, #{dicName}, #{dicParentId}, #{dicRemark}, #{dicOrderNo}, #{dicIsvalid})";
	
	/**
	 * 修改字典SQL
	 */
	final String MODIFY_DIC = "UPDATE sys_dictionary SET dic_name = #{dicName}, dic_remark = #{dicRemark}, dic_orderNo = ${dicOrderNo}, dic_isvalid = ${dicIsvalid}  WHERE dic_id = #{id}";
	
	/**
	 * 删除字典SQL
	 */
	final String DELETE_DIC = "DELETE FROM sys_dictionary WHERE dic_id = #{dicId}";
	
	/**
	 * @describe 根据ID查询字典
	 * @param dicId
	 * @return
	 */
	@Select(GET_BY_ID)
	Dictionary getDic(String dicId);
	
	/**
	 * @description 根据ID查询根目录下的字典信息
	 * @return List<Ztree>
	 */
	@Select(GET_ZTREE_BY_ID)
	List<Ztree> getDictionaryZtree();
	
	/**
	 * @description 保存字典信息
	 * @return Integer
	 */
	@Insert(SAVE_DIC)
	Integer saveDic(Dictionary dic);
	
	/**
	 * 
	 * @description 字典信息修改
	 * @return Integer
	 */
	@Update(MODIFY_DIC)
	Integer modifyDic(Dictionary dic);
	
	/**
	 * 
	 * @description 字典信息删除
	 * @return Integer
	 */
	@Update(DELETE_DIC)
	Integer deleteDic(String dicId);
}
